package com.lz.autotest.project.testmanage.envmanage.controller;

import com.lz.autotest.common.entity.ResponseVo;
import com.lz.autotest.common.web.controller.BaseController;
import com.lz.autotest.common.web.page.TableDataInfo;
import com.lz.autotest.project.testmanage.envmanage.domain.TsstEnv;
import com.lz.autotest.project.testmanage.envmanage.service.TsstEnvService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: X
 * @date: Created in 2023/7/31 11:24
 * @Description: 环境配置
 */
@RestController
@RequestMapping(value = "/tsstEnv")
public class TsstEnvController extends BaseController {

    @Resource
    private TsstEnvService tsstEnvService;

    /**
     * @desc 查询环境列表
     * @author zip.li
     * @date 2023/07/31
     */
    @PreAuthorize("@ss.hasPermi('testmanage:env:list')")
    @GetMapping("/list")
    public TableDataInfo list(TsstEnv env) {
        startPage();
        List<TsstEnv> list = tsstEnvService.selectTsstEnvList(env);
        return getDataTable(list);
    }

    /**
     * @desc 新增
     * @author zip.li
     * @date 2023/07/31
     **/
    @PostMapping("/insert")
    @PreAuthorize("@ss.hasPermi('testmanage:env:insert')")
    public ResponseVo insert(@RequestBody TsstEnv tsstEnv) {
        ResponseVo responseVo = tsstEnvService.checkEnvUnique(tsstEnv);
        if (!responseVo.isSuccess()) {
            return responseVo;
        }
        tsstEnvService.insert(tsstEnv);
        return ResponseVo.success();
    }

    /**
     * @desc 刪除
     * @author zip.li
     * @date 2023/07/31
     **/
    @DeleteMapping("/delete/{ids}")
    @PreAuthorize("@ss.hasPermi('testmanage:env:delete')")
    public ResponseVo delete(@PathVariable Long[] ids) {
        tsstEnvService.delete(ids);
        return ResponseVo.success();
    }

    /**
     * @desc 更新
     * @author zip.li
     * @date 2023/07/31
     **/
    @RequestMapping("/update")
    @PreAuthorize("@ss.hasPermi('testmanage:env:update')")
    public ResponseVo update(@RequestBody TsstEnv tsstEnv) {
        ResponseVo responseVo = tsstEnvService.checkEnvUnique(tsstEnv);
        if (!responseVo.isSuccess()) {
            return responseVo;
        }
        tsstEnv.setUpdateBy(getUsername());
        tsstEnvService.update(tsstEnv);
        return ResponseVo.success();
    }

    /**
     * @desc 设置默认
     * @author X
     * @Date 2023/07/31
     **/
    @RequestMapping("/updateDefault/{id}")
    @PreAuthorize("@ss.hasPermi('testmanage:env:default')")
    public ResponseVo updateDefault(@PathVariable Long id) {
        tsstEnvService.updateDefault(id);
        return ResponseVo.success();
    }

}
